package io.renren.modules.wx.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.wx.entity.CourseEvaluationEntity;
import io.renren.modules.wx.service.CourseEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * @author linmingze
 * @email ${email}
 * @date 2022-10-18 10:41:32
 */
@RestController
@RequestMapping("wx/courseevaluation")
public class CourseEvaluationController {
    @Autowired
    private CourseEvaluationService courseEvaluationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = courseEvaluationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{evaluationId}")
    public R info(@PathVariable("evaluationId") Integer evaluationId) {
        CourseEvaluationEntity courseEvaluation = courseEvaluationService.getById(evaluationId);

        return R.ok().put("courseEvaluation", courseEvaluation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CourseEvaluationEntity courseEvaluation) {
        courseEvaluationService.save(courseEvaluation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CourseEvaluationEntity courseEvaluation) {
        courseEvaluationService.updateById(courseEvaluation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] evaluationIds) {
        courseEvaluationService.removeByIds(Arrays.asList(evaluationIds));

        return R.ok();
    }

    @RequestMapping("/content/{courseId}")
    public R getContentByCourseId(@PathVariable("courseId") Integer courseId){
        List<CourseEvaluationEntity> contents = courseEvaluationService.getEvaluationByCourseId(courseId);
        return R.ok().put("content", contents);
    }
}
